<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>店员管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		label {
			margin-left:10px;
	}
	</style>
	<script type="text/javascript">
		global.bossPassword = "${fns:getStore().bossPassword}";
		var copyObj = {};
		$(document).ready(function() {
			$("#contentTable tbody tr").click(function(){
				sessionStorage.bonusPageNo = $("#pageNo").val();
				var id = this.id;
				var item = $("#opreation-"+ id);
				if(item.length > 0) {
					item.remove();
					this.event.stopPropagation();
					return;
				}
				$(".opreationTR").removeClass("opreationTR");
				$(".opreation").remove();
				var html= "<tr id='opreation-" + id + "' class='opreation'><td colspan='6'>";
					html += '<a data-role="button" data-inline="true" onclick="bossPasswordPopup(\'${ctx}/employee/storeBonusSettingCard/?employeeId=' + id + '\')">修改提成设定</a>';
					html += '<a data-role="button" data-inline="true" onclick="firstCopy('+id+')">复制提成设定</a>';
					html += '</td></tr>';
				$("#" + id).after(html);
				$(this).addClass("opreationTR");
				$("#contentTable").trigger("create");
				this.event.stopPropagation();
			});
			var currentSelectId = '${currentSelectId}';
			if(currentSelectId){
				$("#"+currentSelectId).addClass("opreationTR");
			} else {
				$("#contentTable tbody tr:first-child").addClass("opreationTR");
			}
		});
		
		function firstCopy(employeeId){
			var submit = function(){
				$('#copySelection').popup('open');
            }
			bossPasswordPopup(submit);
			copyObj.employeeId = employeeId;
		}
		
		function secondCopy(){
			$('#copySelection').popup('close');
			var type = $("input[name='copyType']:checked").val();
			if(type == "0"){
				copyObj.type = "0";
				copyObj.formId = "";
				$('#dialog-copyConfirm').popup('open');
			} else {
				copyObj.type = "1";
				selectEmployee();
			}
		}
		
		function thirdCopy(ifModify){
			copyObj.ifModify = ifModify;
			$('#dialog-copyConfirm').popup('close');
			copySubmit();
		}
		
		function copySubmit() {
			jQuery.ajax({  
		          type : 'POST',  
		          url : '${ctx}/employee/employee/copyBonus',  
		          data : copyObj,
		          success : function(data) {
		        	  showTip("复制成功");
		          },  
		          error : function(data) {  
		        	  showTip("查询失败");
		          }  
		    }); 
		}
		
		function selectEmployee() {
			var func = function(obj){
				copyObj.from = obj.id;
				$('#dialog-copyConfirm').popup('open');
			};
			var extIds = copyObj.employeeId + ",";
			var url = '${ctx}/employee/employee/employeeData'; 
			global.singleSelectDialog(url, '添加员工', extIds, func);
		};
		
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>
<div class="icon-buttons">
	<a data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="${ctx}">返回</a>
</div>
<nav data-role="navbar">
	    <ul>
	        <li><a class="ui-btn-active" href="${ctx}/employee/employee/bonusList">员工提成设定</a></li>
	        <li><a href="${ctx}/employee/storeBonusSettingTemplateCard/">提成模板设定</a></li>
	    </ul>
	</nav>
	<form:form id="searchForm" modelAttribute="employee" action="${ctx}/employee/employee/bonusList" method="post">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<label> 姓名 ：</label>
		<form:input type="search" id="name" path="name" htmlEscape="false" maxlength="50"/>
		<input id="btnSubmit" type="submit" value="查询" data-inline="true"/>
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
		<thead><tr><th>姓名</th><th>性别</th><th width="200">职位</th><th>电话</th></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="employee">
			<tr id="${employee.id}">
				<td>${employee.name}</td>
				<td>${fns:getDictLabel(employee.gender, 'gender', '')}</td>
				<td>${employee.storeRole.name}</td>
				<td>${employee.mobile}</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	
	<div data-role="popup" id="copySelection"
		data-overlay-theme="a" data-theme="c" data-dismissible="false"
		class="ui-corner-all">
		<div data-role="header" data-theme="a" class="ui-corner-top">
			<h1>温馨提示</h1>
		</div>
		<div data-role="content" style="width:300px" data-theme="d"
			class="ui-corner-bottom ui-content">
				<h3 class="ui-title">请选择复制类型:</h3>
				<input type="radio" name="copyType"  id="type1" value="0" checked="checked" /> 
				<label for="type1">从设定模板复制</label> 
				<input type="radio" name="copyType" id="type2"  value="1" /> 
				<label for="type2">从其他员工复制</label>
		</div>
		<div data-theme="a" data-role="footer">
			<fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
				<button data-inline="true" onclick="secondCopy()">确定</button>
				<a href="#" data-rel="back" data-role="button" data-inline="true">取消</a>
			</fieldset>
		</div>
	</div>
	
	<div data-role="popup" id="dialog-copyConfirm" data-overlay-theme="a" data-theme="c" data-dismissible="false" class="ui-corner-all">
	    <div data-role="header" data-theme="a" class="ui-corner-top">
	        <h1>温馨提示</h1>
	    </div>
	    <div data-role="content" style="width:430px" data-theme="d" class="ui-corner-bottom ui-content">
	        <h3 class="ui-title">此操作将会使用提成设定模板里的设定数据，是否需要覆盖已有设定，或者只追加数据？</h3>
	        <br />
	    </div>
	    <div data-theme="a" data-role="footer">
		    <fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
	    		<button data-inline="true" onclick="thirdCopy(1)">覆盖</button>
	    		<button data-inline="true" onclick="thirdCopy(0)">追加</button>
	        	<a href="#" data-role="button" data-inline="true"  data-rel="back" data-theme="a">取消</a>
	    	</fieldset>
	    </div>
    </div>
</body>
</html>
